<template>
	<view class="body" :style="{'background':'url('+PayImgUrl+')'}">
		<view class="btn" @click="sumbit()"></view>
	</view>
</template>

<script>
export default {
	data() {
		return {
		  PayImgUrl: uni.getStorageSync('imgUrl'), //页面地址
		  orderNo:'',
		  timer:null,
		  radio: '',
		  payType:'',
		  total: uni.getStorageSync('payPrice') || 100,
		  payTypeList: [],
		}
	},
	created() {
		this.payTypeList = []
		var anzuo = uni.getSystemInfoSync().platform === 'android' ? '1' : '0'
		this.$api.payChanle({iccid: uni.getStorageSync('iccid') || '',anzuo}).then(res=>{
			for (let i = 0; i < res.data.length; i++) {
				if(res.data[i].payType !=10){
					this.payType=res.data[i].payType;
				}
			}
		})
		// this.selectIsAutoState()
	},
	onHide() {
		clearInterval(this.timer)
	},
	beforeDestroy(){
		clearInterval(this.timer)
	},
	onShow() {
		if(uni.getStorageSync('orderNo')) {
			this.orderChange(uni.getStorageSync('orderNo'))
		}
	},
	methods: {
		//查询支付结果
		orderChange(orderNo){
			this.$api.orderState({orderNo}).then(res=>{
				if(res.code === '200'){
					// uni.showModal({
					// 	title:"支付通知",
					// 	content:"您已完成支付！请稍后刷新页面查询到账",
					// 	success(ress){
					// 		uni.switchTab({
					// 			url:"/pages/index/index"
					// 		})
					// 	}
					// })
					uni.switchTab({
						url:"/pages/index/index"
					})
				}
			})
		},
		sumbit() {
			var params = {
				iccid: uni.getStorageSync('iccid') || '',
				amount: 100 * 100, //固定值
				giftBalance: 0, //固定值
				yucun: 1, //固定值
				payType: this.payType, // 固定微信支付
			}
			if(!this.payType){
				uni.showToast({
					title: '缺少支付方式！',
					icon: 'none'
				})
				return
			}
			//支付接口
			this.$api.priceOrder(params).then(res=>{
				if(res.code === '200'){
					console.log(params)
					uni.setStorageSync('orderNo',res.data.orderNo)
					if(params.payType === 80){ //支付宝h5支付
						//#ifdef H5
							window.location.href=res.data.payInfo;
						//#endif
						//#ifdef APP-PLUS
							plus.runtime.openURL(res.data.payInfo)
						//#endif
					}else if(params.payType === 88){//支付宝app支付
						uni.requestPayment({
							provider: 'alipay',
							orderInfo: res.data.payInfo, //支付宝订单数据
							success: function(res) {
								console.log('success:' + JSON.stringify(res));
							},
							fail: function(err) {
								console.log('fail:' + JSON.stringify(err));
							}
						});
					}else if(params.payType === 20){// 微信h5支付
						//#ifdef H5
							window.location.href=res.data.payInfo;
						//#endif
						//#ifdef APP-PLUS
							plus.runtime.openURL(res.data.payInfo)
						//#endif
					}else if(params.payType === 22||params.payType === 23||params.payType === 24){ //微信小程序支付
						//TODO
						// this.pay.wxpay(1,res.data);
						//#ifdef APP-PLUS
						var data = res.data
						plus.share.getServices(childRes => {
							let sweixin = null;
							for (let i in childRes) {
								if (childRes[i].id == 'weixin') {
									sweixin = childRes[i];
								}
							}
							//唤醒微信小程序
							if (sweixin) {
								sweixin.launchMiniProgram({
									id: 'gh_1c60bd6e4f46', //小程序原始id
									type:0, //小程序版本  0-正式版； 1-测试版； 2-体验版。
									// path: '/pages/index/index?price=100&payType=22&orderNo=HFDKG202311010000067755' //小程序的页面,用传的参数在小程序接值判断跳转指定页面
									path: '/pages/index/index?payType='+data.payType+ '&orderNo='+data.orderNo //小程序的页面,用传的参数在小程序接值判断跳转指定页面
								},
								//目标小程序点击返回App后执行的回调,在此接收binderror="launchAppError"的参数
								res1 => {
									console.log(res1)
								},err => {
									console.log(err)
								});
							}
						});
						//#endif
					}else{ //扫码支付 
						var param = {
							orderNo:res.data.orderNo,
							payUrl:res.data.payUrl,
							payImg:res.data.payImg,
						}
						let base64 = new this.$base64()
						uni.navigateTo({
							url:'/pages/scanCodePayment/index?params='+base64.encode(JSON.stringify(param))
						})
					}
				}else{
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				}
			})
		}

	  
	},
 
}
</script>

<style lang="scss">
	.body{
	    background-repeat: no-repeat !important;
	    background-position: center !important;
	    background-size: 100% 100% !important;
	    width:100%;
	    height:100vh;
	    position: relative;
	    .btn{
	        width: 325px;
	        position: fixed;
	        bottom: 20px;
	        left: 0px;
	        right: 0px;
	        margin: auto;
	        height: 64px;
	        background: url('../../static/images/6fdec6ce.png')no-repeat center;
	        background-size: 100% 100%;
	    }
	    .v-dialog{
	        position:absolute;
	        width:100%;
	        height:100%;
	        top:0;
	        bottom: 0;
	        left:0;
	        right:0;
	        margin:auto;
	        .v-dialog-bg{
	            position: fixed;
	            background: rgba(0,0,0, .7);
	            top:0;
	            bottom: 0;
	            left:0;
	            right:0;
	            margin:auto;
	            width:100%;
	            height:100%;
	        }
	        .v-dialog-close{
	            width:22px;
	            height:22px;
	            // margin:0 auto;
	            // margin-top:20px;
	            position: fixed;
	            top:0;
	            bottom:-300px;
	            left:0;
	            right:0;
	            margin:auto;
	            image{
	               width:22px;
	               height:22px;
	               cursor: pointer;
	            }
	        }
	        .v-dialog-content{
	            position: fixed;
	            top:0;
	            bottom: 0;
	            left:0;
	            right:0;
	            margin:auto;
	            width: 275px;
	            height: 210px;
	            background: url('../../static/images/t_c1.png') no-repeat center;
	            background-size:100% 100%;
	            .number{
	                position: absolute;
	                font-size: 52px;
	                font-weight: 600;
	                color: #b33a04;
	                left: 104px;
	                top: 28px;
	                border-radius: 100%;
	                height: 72px;
	                line-height: 68px;
	            }
	            .input{
	                background: rgb(255, 255, 255);
	                width: 200px;
	                height: 40px;
	                margin: auto;
	                margin-bottom: 10px;
	                border-radius: 12px;
	                text-align: center;
	                line-height: 40px;
	                font-size: 25px;
	                color: rgb(177, 54, 0);
	                position: absolute;
	                bottom:54px;
	                display: flex;
	                left:0;
	                right:0;
	                justify-content: center;
	                align-items: center;
	            }
	            .sumbit_btn{
	                width: 175px;
	                height: 46px;
	                position: absolute;
	                bottom:8px;
	                display: flex;
	                left:0;
	                margin: auto;
	                right:0;
	                background: url('../../static/images/a2.png') no-repeat center;
	                background-size:100% 100%;
	            }
	        }
	    }
	}
</style>